home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2003 March / DPPCPRO0303.ISO / Components / Microsoft ASP / _SETUP.1 / MSDBUpdateHandler.asp < prev    next >
Encoding:
Text File  |  1998-11-20  |  9.4 KB  |  257 lines

  1. <%@ LANGUAGE="JSCRIPT" %>
  2. <%Response.Buffer = true%>
  3. <HTML>
  4. <HEAD>
  5.    <TITLE>MSDBUpdate Form Handler</TITLE>
  6.    <META NAME="Author" CONTENT="Application Methods Inc.">
  7. </HEAD>
  8. <BODY>
  9.  
  10.  
  11. <br>
  12. <!--#INCLUDE FILE="MSGlobal.inc"-->
  13. <!--#INCLUDE FILE="MSDBConnection.inc"-->
  14. <!--#INCLUDE FILE="MSDBUpdate.inc"-->
  15.  
  16. <%
  17. write("<h3>Error Output:</h3>");
  18. write("<p>If you are seeing this page, an ASP or database server processing error has occurred. Please report the errors on this page to your server or database administrator.<P>");
  19.  
  20. ////////////////////////////////////////////////////////////////////
  21. //                                                                //
  22. //   Fusion ASP Components                                          //
  23. //   Custom Form Handler: MSDBUpdateHandler                       //
  24. //                                                                //
  25. ////////////////////////////////////////////////////////////////////
  26. /*
  27.  
  28. Object:       MSDBUpdateHandler 
  29.  
  30. Version:      1.0  9/24/97
  31.  
  32. Written By:   Application Methods, Inc.
  33.               6300 Southcenter Blvd.
  34.               Seattle, WA 98188
  35.               (206) 244-2400
  36.               http://www.appmethods.com
  37.  
  38. Technical Overview: 
  39. Construct DatabaseConnection object
  40. Construct UpdateTable object 
  41. Check for expected DatabaseConnection property existances and populate object;
  42.     type
  43.     user
  44.     password
  45.     server
  46.     database
  47.  if all exists call connect()
  48.  
  49.  Check for expected UpdateTable property existances and populate object;
  50.    action
  51.    tableName
  52.    primaryKeyFieldCount
  53.    primaryKeyFieldNames
  54.    primaryKeyFieldValues
  55.       
  56.    Extract field info:
  57.    field count
  58.    fieldNames
  59.    fieldValues
  60.  if all exist, construct object and call execute();
  61.  
  62. =====================================================================*/
  63.  
  64. // Variables
  65.   var pre = "amaspHidden_";              // Prefix on all hidden fields
  66.   var preName = "amaspComponent_";       // Prefix on submiting button name, for name identification
  67.   var clientPre = "NETSCAPE_ASP";        // Client & Server URL Client object maintenance prefix
  68.   var dbObjName ;                        // Hard coded name at this point
  69.   var dbDatabaseType = "";
  70.   var dbODBCDatabaseType = "";
  71.   var dbDatabaseServer = "";
  72.   var dbUserName = "";
  73.   var dbPassword = "";
  74.   var dbGlobalConn = "";
  75.  
  76.  
  77. // Create new, clean request object
  78.   write("\r\n<BR>Creating new, clean request object...");
  79.   var myRequest = new NewRequest();
  80. // Debugging function //========================================================================
  81.   viewObject(myRequest.newRequest,"Request");
  82.  
  83. // Construct objects
  84.   write("\r\n<BR>Creating new database objects...");
  85.   // Preserve old globalConn flag in case it is using the initial page since
  86.   // we don't want to write over it.
  87.   var oldProjInitPage = Application("globalConn");
  88.   upd1 = new MSDBUpdate();
  89.   dbObjName = upd1.dataSource;       // Hard coded name at this point
  90.  
  91.   Application("globalConn") = oldProjInitPage;
  92.  
  93.   // Get database component properties
  94.   if (Application("globalConn")!="true") { 
  95.       // Get database properties from Request Object
  96.       dbDatabaseType = myRequest.newRequest[pre+dbObjName+"_databaseType"]; 
  97.       dbODBCDatabaseType = myRequest.newRequest[pre+dbObjName+"_ODBCDatabaseType"]; 
  98.       dbDatabaseServer = myRequest.newRequest[pre+dbObjName+"_databaseServer"]; 
  99.       dbUserName = myRequest.newRequest[pre+dbObjName+"_userName"]; 
  100.       dbPassword = myRequest.newRequest[pre+dbObjName+"_password"]; 
  101.       dbGlobalConn = myRequest.newRequest[pre+dbObjName+"_globalConn"]; 
  102.  
  103.       // Create database object
  104.       // Must pass all properties in constructor because of values used 
  105.       // in function in the constructor
  106.       eval(dbObjName + " = new MSDBConnection(\""+dbObjName+"\",\""
  107.                                              +dbDatabaseType+"\",\""
  108.                                              +dbODBCDatabaseType+"\",\""
  109.                                              +dbDatabaseServer+"\",\""
  110.                                              +dbUserName+"\",\""
  111.                                              +dbPassword+"\",\""
  112.                                              +dbGlobalConn+"\")");
  113.  
  114.    }
  115.  
  116. // Get Update component properties 
  117. // Get button name 
  118.   for (prop in myRequest.newRequest) {
  119.       if (prop.indexOf(preName) == 0) {
  120.           var no = preName.length;
  121.           var pno = prop.length;
  122.           if ((prop.substring(pno-2,pno).toUpperCase() == ".X") || (prop.substring(pno-2,pno).toUpperCase() == ".Y")) {
  123.               pno = pno-2;  
  124.         }
  125.           upd1.name = prop.substring(no,pno);
  126.       }
  127.   }
  128.  
  129. // Proceed only if name found
  130. if (upd1.name != "") {
  131.     var updateButtonName = upd1.name;
  132.  
  133.   // Get Update properties
  134.   upd1.tableName = myRequest.newRequest[pre+updateButtonName+"_tableName"]
  135.   upd1.action = myRequest.newRequest[pre+updateButtonName+"_action"]
  136.   upd1.primaryKeyFieldCount = myRequest.newRequest[pre+updateButtonName+"_primaryKeyFieldCount"]
  137.   upd1.errorURL = myRequest.newRequest[pre+updateButtonName+"_errorURL"]
  138.   upd1.successURL = myRequest.newRequest[pre+updateButtonName+"_successURL"]
  139.  
  140. // Proceed only if counts found
  141. if (upd1.action != "modify" || upd1.action != "delete" || (upd1.action != "add" && upd1.primaryKeyFieldCount+"" != "")) {
  142.  
  143. // Get primary key field names and values
  144.   upd1primaryKeyFieldNames = new Array();
  145.   upd1primaryKeyFieldValues = new Array();
  146.   upd1primaryKeyFieldDataTypes = new Array();
  147.   
  148.   for (var fcnt=0; fcnt < parseInt(upd1.primaryKeyFieldCount,10); fcnt++) {
  149.     upd1primaryKeyFieldNames[fcnt] = "|";
  150.     upd1primaryKeyFieldValues[fcnt] = "|";
  151.     upd1primaryKeyFieldDataTypes[fcnt] = "|";
  152.   }
  153.  
  154.   //debug("Getting primary key field names and values...")
  155.   write("\r\n<BR>Getting primary key field names and values...")
  156.   for (prop in myRequest.newRequest) {
  157.     for (var fcnt=0; fcnt < parseInt(upd1.primaryKeyFieldCount,10); fcnt++) {
  158.         
  159.       if (prop == pre+updateButtonName+"_primaryKeyFieldNames"+fcnt) {
  160.            upd1primaryKeyFieldNames[fcnt] = myRequest.newRequest[prop];
  161.       }
  162.       if (prop == pre+updateButtonName+"_primaryKeyFieldValues"+fcnt) {
  163.         upd1primaryKeyFieldValues[fcnt] = myRequest.newRequest[prop];
  164.       }
  165.       if (prop == pre+updateButtonName+"_primaryKeyFieldDataTypes"+fcnt) {
  166.         upd1primaryKeyFieldDataTypes[fcnt] = myRequest.newRequest[prop];
  167.       }
  168.       
  169.     } // end inner for loop
  170.   } // end outer for loop
  171.     
  172. // Proceed only if all expected primary key field names and values found ?? (Later)
  173.  
  174. // if all systems go so far then continue else quit
  175. // Get field names and values
  176.   upd1fieldNames = new Array();
  177.   upd1fieldValues = new Array(); 
  178.   upd1fieldDataTypes = new Array();
  179.   var upd1fieldCount=0;
  180.   
  181.   //debug("Getting field names and values...");
  182.   write("\r\n<BR>Getting field names and values...");
  183.   for ( prop in myRequest.newRequest) {
  184.     
  185.     // Ignore properties with the prefixes defined in pre, preName and clientPre    
  186.     if (prop.indexOf(pre) == -1 && prop.indexOf(preName) == -1 && prop.indexOf(clientPre) == -1) {
  187.        
  188.            upd1fieldNames[upd1fieldCount] = prop;
  189.            upd1fieldValues[upd1fieldCount] = myRequest.newRequest[prop];
  190.            upd1fieldDataTypes[upd1fieldCount] = myRequest.newRequest[pre+prop+"_dataType"];
  191.            
  192.          upd1fieldCount++;
  193.  
  194.     }  // end if
  195.     upd1.fieldCount=upd1fieldCount
  196.   } // end outer for loop
  197.  
  198. // Final assembly
  199.    upd1.primaryKeyFieldNames = upd1primaryKeyFieldNames;
  200.    upd1.primaryKeyFieldValues = upd1primaryKeyFieldValues; 
  201.    upd1.primaryKeyFieldDataTypes    = upd1primaryKeyFieldDataTypes;    
  202.    upd1.fieldNames = upd1fieldNames;
  203.    upd1.fieldValues = upd1fieldValues;
  204.    upd1.fieldDataTypes = upd1fieldDataTypes;
  205.  
  206.    // Tell update object about the database properties so it can use them to make
  207.    // determinations about data types in the SQL statement based on the type of database.
  208.    upd1.ODBCDatabaseType = (Application("globalConn")=="true") ? Session("ODBCDatabaseType") : eval(dbObjName + ".ODBCDatabaseType");
  209.    upd1.databaseType     = (Application("globalConn")=="true") ? Session("databaseType")     : eval(dbObjName + ".databaseType");
  210.  
  211. // Debugging functions =========================================================================
  212. // Emit database properties
  213.    write("\r\n<BR><HR>Outputting database properties...");
  214.    if (Application("globalConn")!="true") 
  215.       eval(dbObjName + ".emitProperties()");
  216.    else
  217.      write("Using Global Database");
  218.  
  219. // Emit updateTable properties
  220.    write("\r\n<BR><HR>Outputting MSDBUpdate properties...");
  221.    upd1.emitProperties();
  222.    
  223.    write("\r\n<BR><HR>Outputting SQL builds...");
  224.    write("\r\n<BR>"+upd1.buildWhereSQL());
  225.    write("\r\n<BR>"+upd1.buildAddSQL());
  226.    write("\r\n<BR>"+upd1.buildModifySQL());
  227.    write("\r\n<BR>"+upd1.buildDeleteSQL());
  228.  
  229.    upd1.execute();
  230.  
  231. } // End key field count not found
  232. else {
  233.    write("\r\n<BR>Required primary key field count not found in hidden fields");
  234.    debug("Required primary key field count not found in hidden fields");
  235.    Response.Clear();
  236.    Response.Redirect (upd1.errorURL);
  237.    Response.End();
  238.  
  239. }
  240.  
  241. } // End name not found
  242. else {
  243.    write("\r\n<BR>Submit button name not found in hidden fields");
  244.    debug("Submit button name not found in hidden fields");
  245.    Response.Clear();
  246.    Response.Redirect (upd1.errorURL);
  247.    Response.End();
  248.  
  249. }
  250.  
  251.  
  252.  
  253. %>
  254.  
  255. </BODY>
  256. </HTML>
  257.